﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Dao.Intermediarios
{
    public class IPCoeficiente:Intermediario
    {
        public override void save<T>(T entity)
        {
            try
            {
                Coeficiente coef = entity as Coeficiente;
                dao.Coeficientes.InsertOnSubmit(coef);
            }
            catch (Exception ex)
            {
                throw new Exception("IPCoeficientes.save - " + ex.Message);
            }
        }

        public override List<T> getAll<T>()
        {
            return (from coef in dao.Coeficientes orderby coef.idParametros select coef).ToList() as List<T>;
        }

        public override List<T> getByCriterio<T>(string att, string op, string val)
        {
            return null; // (from ct in dao.CentroTrabajos where ct.nombreCtroTrab.Contains(val) || ct.codCT.Contains(val) || ct.Edificio.nombreEdificio.Contains(val) orderby ct.codCT select ct).ToList() as List<T>;
        }

        public override IList<T> getCriterioById<T>(string att, string op, int val)
        {
            //throw new NotImplementedException();
            return (from c in dao.Coeficientes where c.idParametros == Convert.ToInt16(val) select c).ToList() as List<T>;    // && c.Activo == true 

        }

        public override object getPorId(int id)
        {
            return (from est in dao.RF_CTs where est.IdCT == id select est);
        }

        public IList<RF_CT> getCCId(int id)
        {
            return (from est in dao.RF_CTs where est.IdCT == id select est).ToList();
        }

        public CentroTrabajo getById(int id)
        {
            try
            {
                return (from ct in dao.CentroTrabajos where ct.IdCentroTrab == id select ct).SingleOrDefault();
            }
            catch (Exception)
            {
                return null;
            }
        }

        public override IList<T> getPorCriterio<T>(string name)
        {
            throw new NotImplementedException();
        }

        public override void Update<T>(T entity)
        {
            throw new NotImplementedException();
        }

        public override void Delete(int id)
        {
            try
            {
                var ct = (from c in dao.CentroTrabajos where c.IdCentroTrab == id select c).SingleOrDefault();

                if (ct != null)
                {
                    dao.CentroTrabajos.DeleteOnSubmit(ct);
                    dao.SubmitChanges();
                }
            }
            catch (Exception)
            {
                throw;
            }
        }

        
    }
}
